package com.youth.fund.hk.hostManager.common.dao.mybatis;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.youth.fund.hk.hostManager.common.dao.IBaseDao;
/**
 * 
 * @author Sunk_Sky
 *
 * 2014年11月9日下午12:58:55
 */
public class BaseMybatisDao <M extends java.io.Serializable, PK extends java.io.Serializable> implements IBaseDao<M , PK>
{
	@Autowired
	@Qualifier("sqlSession")
	protected SqlSession sqlSesstion;

	public SqlSession getSqlSesstion()
	{
		return sqlSesstion;
	}

	public void setSqlSesstion(SqlSession sqlSesstion)
	{
		this.sqlSesstion = sqlSesstion;
	}

	/* (non-Javadoc)
	 * @see com.youth.fund.hk.hostManager.common.dao.IBaseDao#create(java.io.Serializable, java.lang.String)
	 */
	@Override
	public boolean create(M model, String command)
	{
		boolean result = false;
		
		int tem = this.sqlSesstion.insert(command, model);
		
		if(tem > 0 )
		{
			result = true;
		}
		
		return result;
	}

	/* (non-Javadoc)
	 * @see com.youth.fund.hk.hostManager.common.dao.IBaseDao#delete(java.io.Serializable, java.lang.String)
	 */
	@Override
	public boolean delete(M model, String command)
	{
		boolean result = false;
		
		int tem = this.sqlSesstion.delete(command, model);
		
		if(tem > 0)
		{
			result =true;
		}
		
		return result;
	}

	/* (non-Javadoc)
	 * @see com.youth.fund.hk.hostManager.common.dao.IBaseDao#update(java.io.Serializable, java.lang.String)
	 */
	@Override
	public boolean update(M model, String command)
	{
		boolean result = false;
		
		int tem = this.sqlSesstion.update(command, model);
		
		if(tem > 0)
		{
			result = true;
		}
		
		return result;
	}

	/* (non-Javadoc)
	 * @see com.youth.fund.hk.hostManager.common.dao.IBaseDao#query(java.io.Serializable, java.lang.String)
	 */
	@Override
	public List<M> query(M model, String command)
	{
		List<M> list = this.sqlSesstion.selectList(command, model);
		
		return list;
	}

	/* (non-Javadoc)
	 * @see com.youth.fund.hk.hostManager.common.dao.IBaseDao#queryOne(java.io.Serializable, java.lang.String)
	 */
	@Override
	public M queryOne(M model, String command)
	{
		M result = null;
		
		List<M> list = this.query(model, command);
		
		if(list != null && list.size() != 0)
		{
			result = list.get(0);
		}
		return result;
	}

}
